<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    div {
        width: 300px;
        height: 300px;
        border: 1px solid springgreen;
    }

    .show-box {
        display: none;
    }

    input {
        border: 1px solid green;
    }

    .show-box.active {
        display: block;
        position: absolute;
        top: 300px;
        left: 300px;
        background-color: purple;
    }
</style>

<body>
    <div class="input-wrap"> <input type="text">
        <div class="show-box">ewewe</div>
    </div>

</body>
<script>
    const showBox = document.querySelector('.show-box');
    const inputWrap = document.querySelector('.input-wrap')
</script>
<script>
    const on = (obj, ...agrs) => obj.addEventListener(...agrs);
    const defaultValue = ['mousedown', 'touchstart'];
    const useAwayFn = (el, fn, event = defaultValue) => {

        const handle = (e) => {
            fn(el.contains(e.target))
        }
        for (const type of defaultValue) {
            on(document, type, handle, false)
        }

        return handle
    }
    useAwayFn(inputWrap, flag => {
        if (flag) {
            showBox.classList.add('active')
        } else {
            showBox.classList.remove('active')
        }
    })




</script>